/* 
 *  Copyright (C) 2007 Dip. Ing. dell'Informazione, University of Pisa, Italy
 *  http://info.iet.unipi.it/~cng/ns2voip/
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, USA
 */
/*
 */

#ifndef __NS2_VOIP_DECODER_OPTIMAL_H
#define __NS2_VOIP_DECODER_OPTIMAL_H

#include <voip_decoder.h>
#include <map>
#include <vector>

class VoipDecoderOptimal : public VoipDecoder {
public:
	//! Create an empty VoIP decoder.
	VoipDecoderOptimal ();

	//! Tcl interface.
	int command (int argc, const char*const* argv);

protected:
	//! Collect statistics after playout buffering frame by frame.
	void collectFrame (VoipFrame& frame);
	//! Collect statistics after playout buffering talkspurt by talkspurt.
	void collectTalkspurt (unsigned int nframes);
	//! Collect statistics after playout buffering at the end of simulation.
	void collectEnd ();

protected:
	//! Talkspurt data structure.
	struct TalkData {
		//! Delay samples, in seconds.
		std::vector<double> delay_;
		//! Number of frames in this talkspurt.
		unsigned int nframes_;
		//! Number of frames received so far.
		unsigned int received_;

		//! Create an empty talkspurt data structure.
		TalkData () {
			nframes_  = 0;
			received_ = 0;
		}
	};

	//! One talkspurt data structure for each talkspurt ID.
	std::map<unsigned int, TalkData> talkData_;
};

#endif // __NS2_VOIP_DECODER_OPTIMAL_H
